package com.functest.orm

import com.functest.framework.BaseFunctionalTest
import com.functest.orm.TestData.Student
import com.functest.orm.TestData.StudentStatus
import org.testng.annotations.Test



/**
 * @author: DavydovMD
 * Date: 05.04.13
 * Time: 14:10
 */

class DbMappersTests extends BaseFunctionalTest {

/** *************/
/*MapperBinding*/
/** *************/

//nothing to do here - setters-getters only

/** **************/
/*FieldReference*/
/** **************/

//nothing to do here



/** **********************/
/** **********************/
/** **********************/

    @Test
    void sampleTableMapperTest() {
        asTest {

            TestData.Student stud
            asStep('byid() with primary key value specified only')
                    {
                        stud = Student.provider.byId(2)
                        assert stud.firstName == 'Ivan'
                        assert stud.lastName == 'Ivanov'
                        assert stud.status == StudentStatus.Graduate
                    }

            asStep('byFieldValueFirst with custom field') {
                TestData.Student looser = Student.provider.byFieldValueFirst('lastName', 'Sidorov')
                assert looser.firstName == 'Sidor'
            }

        }
    }

    @Test
    void sampleQueryBuilderTest() {
        def query = Student.provider.query()
        QueryExecutor qe = query.allFields()
                .where('firstName', ConditionOp.EQ, 'Ivan')
                .or('status', ConditionOp.EQ, StudentStatus.Expelled)
                .build()

        List<TestData.Student> studentz = Student.provider.usingQuery(qe)
        assert studentz.size() == 3
    }

}

